﻿@using System.Reflection
@using Sharp.DataTransferObject
@using Sharp.Infrastructure
@using Sharp.Portal.Interface
@{
    var x = Html.X();
    var devButton = new Button
    {
        Text = "开发工具",
        Visible = WebServer.GetIP() == "127.0.0.1",
        Menu =
            {
                x.Menu().Items(x.MenuItem().Text("权限初始化").Icon(Icon.BookGo).Href("/OP/Home/Index").HrefTarget("_blank"))
            }
    };


    Assembly assembly = typeof(MvcApplication).Assembly;
    foreach (var type in assembly.GetTypes())
    {
        if (type.GetInterface(nameof(INavigation)) != null)
        {
            var navigation = Activator.CreateInstance(type) as INavigation;
            if (navigation.IsDevOnly)
            {
                var list = navigation.Navigation().ToList();

                list.ForEach(p =>
                {
                    if (p.IsShortcut) return;
                    devButton.Menu[0].Items.Add(x.MenuItem().Text(p.Title).Icon(Icon.Box).Href(p.Route).HrefTarget("_blank").ToComponent());
                });

            }
        }
    }
}

@(x.Toolbar().Region(Region.North).Split(false).Items(items =>
{
    items.Add(new ToolbarTextItem { Text = "欢迎您：" });
    items.Add(new Hyperlink { Text = Model.UserName });
    items.Add(new ToolbarSpacer());
    items.Add(new ToolbarSeparator());
    items.Add(new ToolbarSpacer());


    items.Add(new Hyperlink { Text = "首页", NavigateUrl = "/" });

    items.Add(new ToolbarSpacer());
    items.Add(new ToolbarSeparator());
    items.Add(new ToolbarSpacer());

    items.Add(new Hyperlink { Text = "资料" });

    items.Add(new ToolbarSpacer());
    items.Add(new ToolbarSeparator());
    items.Add(new ToolbarSpacer());

    items.Add(new Hyperlink { Text = string.Format("消息 ({0})", Model.NewMessageCount) });

    items.Add(new ToolbarSpacer());
    items.Add(new ToolbarSeparator());
    items.Add(new ToolbarSpacer());

    items.Add(new Hyperlink { Text = "帮助" });

    items.Add(new ToolbarFill());
    items.Add(devButton);
    items.Add(new Button
    {
        Text = "账号",
        Menu =
        {
            x.Menu().Items(
                x.MenuItem().Text("注销登录").Icon(Icon.DoorOut).DirectClickUrl("/Platform/Account/Logout"),
                x.MenuItem().Text("关于").Icon(Icon.Information).DirectClickUrl(Url.Action("About"))
                )
        }
    });
    items.Add(new Button()
    {
        Text = "设置",
        Icon = Icon.Cog,
        DirectClickUrl=Url.Action("Custom")
    });


})
)